package org.example.sward.tooffer;

import java.util.Stack;

public class MinStack {
    Stack<Integer> A,B;
    public MinStack(){
        A = new Stack<>();
        B = new Stack<>();
    }

    public void push(int x){
        A.push(x);
        if(B.isEmpty() || B.peek() >= x){
            B.add(x);
        }
    }

    public void pop(){
        if(A.pop().equals(B.peek())){
            B.pop();
        }
    }
    public int top(){
        return A.peek();
    }
    public int min(){
        return B.peek();
    }

    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(-2);
        minStack.push(0);
        minStack.push(-3);
        minStack.min();  // --> 返回 -3.
        minStack.pop();
        minStack.top();    //  --> 返回 0.
        minStack.min();  // --> 返回 -2.



    }
}

